package com.yun.blog.config;

import com.yun.blog.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * title        : InterceptorConfig
 * projectName  : dantouBlog-back
 * description  : 拦截器配置类,这个配置类必须通过实现 WebMvcConfigurer接口
 *                需要 @Bean 注入拦截器，否则拦截器不能使用service层的方法
 * author       : simple
 * date         : 2022/11/25下午2:41
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public TokenInterceptor tokenInterceptor() {
        return new TokenInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor())
                .addPathPatterns("/admin/**");
    }

}
